import sys
import datetime
import time
import logging
class Logger(object):
	def __init__(self,filename = "Default.log"):
		self.terminal = sys.stdout
		#self.log = open(filename,"a")
		self.logger = logging.getLogger(__name__)
		self.logger.setLevel(level = logging.INFO)
		self.handler = logging.FileHandler(filename)
		self.handler.setLevel(logging.INFO)
		formatter = logging.Formatter('%(message)s')
		self.handler.setFormatter(formatter)
		self.logger.addHandler(self.handler)


	def write(self,message):
		if message != '\n':
			message = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +' [INFO] ' + message
			self.logger.info(message)
		self.terminal.write(message)
		

	def write_to_log(self,message):
		message = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +' [INFO] ' + message
		self.logger.info(message)

	def remove():
		self.logger.removeHandler(self.handler)
		
	def flush(self):
		pass
#+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+"
nowTime = time.strftime("%Y-%m-%d-%H_%M_%S",time.localtime(time.time())) 
sys.stdout = Logger("TcpLong.txt")